package com.xja.tt.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xja.tt.bean.Search;
import com.xja.tt.bean.User;
import com.xja.tt.mapper.UserMapper;
import com.xja.tt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther asus
 * @date 2021/12/22
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo<User> findAllUser(Search search) throws Exception {
        Integer pageNumInt=1;
        Integer pageSizeInt=4;
        if (search.getPageNum()!=null && !"".equals(search.getPageNum())){
            pageNumInt=Integer.valueOf(search.getPageNum());
        }
        if (search.getPageSize()!=null && !"".equals(search.getPageSize())){
            pageSizeInt=Integer.valueOf(search.getPageSize());
        }
        PageHelper.startPage(pageNumInt,pageSizeInt);
        List<User> userList = userMapper.findAllUser();
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        return pageInfo;
    }
}
